home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / PercentControl.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  5.2 KB  |  166 lines

  1. package symantec.itools.db.awt;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7. import java.awt.Panel;
  8. import symantec.itools.db.pro.ProjBinder;
  9. import symantec.itools.db.pro.ProjLink;
  10. import symantec.itools.db.pro.RelationView;
  11. import symjava.sql.SQLException;
  12.  
  13. public class PercentControl extends Panel implements ProjLink {
  14.    ProjBinder m_ProjBinder1;
  15.    ProjBinder m_ProjBinder2;
  16.    public boolean m_bshowAsPcnt = true;
  17.    public boolean m_bshowNumbers = true;
  18.    private float m_Used;
  19.    private float m_Limit = 1.0F;
  20.    private String m_Column1;
  21.    private String m_Column2;
  22.    private boolean bfirstPass = true;
  23.    private int m_treatBlankAs;
  24.    private boolean m_DynamicUpdate = false;
  25.  
  26.    public void setShowAsPercent(boolean percent) {
  27.       this.m_bshowAsPcnt = percent;
  28.    }
  29.  
  30.    public void setShowNumbers(boolean numbers) {
  31.       this.m_bshowNumbers = numbers;
  32.    }
  33.  
  34.    public void setLimit(int limit) {
  35.       this.m_Limit = (float)limit;
  36.    }
  37.  
  38.    public void setAmountUsed(int used) {
  39.       this.m_Used = (float)used;
  40.    }
  41.  
  42.    public void setBinding(RelationView relView, String column1, String column2) {
  43.       int projNumber = 0;
  44.       if (column1 != null) {
  45.          try {
  46.             this.m_Column1 = new String(column1);
  47.             projNumber = relView.findProjByName(this.m_Column1);
  48.             relView.bindProj(projNumber, this);
  49.          } catch (SQLException Ex) {
  50.             System.out.println("SQLException from PercentControl.setBinding: " + ((Throwable)Ex).getMessage());
  51.          }
  52.       }
  53.  
  54.       if (column2 != null) {
  55.          try {
  56.             this.m_Column2 = new String(column2);
  57.             projNumber = relView.findProjByName(this.m_Column2);
  58.             relView.bindProj(projNumber, this);
  59.          } catch (SQLException Ex) {
  60.             System.out.println("SQLException from PercentControl.setBinding: " + ((Throwable)Ex).getMessage());
  61.          }
  62.       }
  63.    }
  64.  
  65.    public void init(ProjBinder binder) {
  66.       if (this.bfirstPass) {
  67.          this.m_ProjBinder2 = binder;
  68.          this.bfirstPass = false;
  69.       } else {
  70.          this.m_ProjBinder1 = binder;
  71.       }
  72.    }
  73.  
  74.    public void notifyDataChange(ProjBinder binder) {
  75.       try {
  76.          if (binder.equals(this.m_ProjBinder1)) {
  77.             this.m_Limit = binder.getFloat();
  78.          } else {
  79.             this.m_Used = binder.getFloat();
  80.          }
  81.       } catch (SQLException e) {
  82.          System.out.println(((Throwable)e).getMessage());
  83.       }
  84.  
  85.       ((Component)this).repaint();
  86.    }
  87.  
  88.    public boolean notifySetData(ProjBinder binder) throws SQLException {
  89.       return true;
  90.    }
  91.  
  92.    public void setTreatBlankAs(String blank) {
  93.       if ((new String(blank)).toUpperCase().equals("DEFAULT")) {
  94.          this.m_treatBlankAs = 0;
  95.       } else if ((new String(blank)).toUpperCase().equals("NULL")) {
  96.          this.m_treatBlankAs = 1;
  97.       } else {
  98.          if ((new String(blank)).toUpperCase().equals("EMPTY")) {
  99.             this.m_treatBlankAs = 2;
  100.          }
  101.  
  102.       }
  103.    }
  104.  
  105.    public void setDynamicUpdate(boolean update) {
  106.       this.m_DynamicUpdate = update;
  107.    }
  108.  
  109.    public void paint(Graphics g) {
  110.       float percentage = this.m_Used / this.m_Limit;
  111.       g.setColor(Color.black);
  112.       Dimension dim = ((Component)this).size();
  113.       int w = dim.width;
  114.       int h = dim.height;
  115.       int intRectW = (int)((double)w * 0.96);
  116.       int intRectH = (int)((double)h * 0.9);
  117.       g.drawRect(0, 0, intRectW, intRectH);
  118.       int barH = (int)((double)intRectH * 0.28);
  119.       int barY = (int)((double)intRectH * 0.28);
  120.       int totalBarLength = (int)((double)intRectW * 0.8);
  121.       float position = (float)totalBarLength * percentage;
  122.       int BarBoundary = (intRectW - totalBarLength) / 2;
  123.       g.drawLine((int)((double)intRectW * 0.1), (int)((double)intRectH * 0.22), (int)((double)intRectW * 0.1), (int)((double)intRectH * 0.67));
  124.       g.drawLine((int)((double)intRectW * 0.9), (int)((double)intRectH * 0.22), (int)((double)intRectW * 0.9), (int)((double)intRectH * 0.67));
  125.       if (this.m_Used > this.m_Limit) {
  126.          g.fillRect(BarBoundary, barY, totalBarLength, barH);
  127.          g.setColor(Color.red);
  128.          if (position - (float)totalBarLength > (float)totalBarLength) {
  129.             position = (float)(totalBarLength * 2);
  130.          }
  131.  
  132.          g.fillRect(BarBoundary, barY, (int)position - totalBarLength, barH);
  133.          g.setColor(Color.black);
  134.          if (h > 24 && this.m_bshowNumbers) {
  135.             g.drawString((new Float(this.m_Limit)).toString(), (int)((double)intRectW * 0.072), (int)((double)intRectH * 0.9400000000000001));
  136.             if (this.m_bshowAsPcnt) {
  137.                g.drawString((new Integer((new Float(100.0F * percentage)).intValue())).toString() + "%", (int)((double)((float)BarBoundary + (position - (float)totalBarLength)) * 0.9400000000000001), (int)((double)intRectH * 0.9400000000000001));
  138.                return;
  139.             }
  140.  
  141.             g.drawString((new Float(this.m_Used)).toString(), (int)((double)((float)BarBoundary + (position - (float)totalBarLength)) * 0.9400000000000001), (int)((double)intRectH * 0.9400000000000001));
  142.             return;
  143.          }
  144.       } else {
  145.          g.setColor(Color.red);
  146.          g.fillRect(BarBoundary, barY, totalBarLength, barH);
  147.          g.setColor(Color.green);
  148.          g.fillRect(BarBoundary, barY, (int)position, barH);
  149.          g.setColor(Color.black);
  150.          if (h > 24 && this.m_bshowNumbers) {
  151.             g.drawString("0", (int)((double)intRectW * 0.08800000000000001), (int)((double)intRectH * 0.9400000000000001));
  152.             g.drawString((new Float(this.m_Limit)).toString(), (int)((double)intRectW * 0.86), (int)((double)intRectH * 0.9400000000000001));
  153.             if (this.m_Used != this.m_Limit && this.m_Used != 0.0F && h > 24) {
  154.                if (this.m_bshowAsPcnt) {
  155.                   g.drawString((new Integer((new Float(100.0F * percentage)).intValue())).toString() + "%", (int)((double)((float)BarBoundary + position) * 0.9400000000000001), (int)((double)intRectH * 0.9400000000000001));
  156.                   return;
  157.                }
  158.  
  159.                g.drawString((new Float(this.m_Used)).toString(), (int)((double)((float)BarBoundary + position) * 0.9400000000000001), (int)((double)intRectH * 0.9400000000000001));
  160.             }
  161.          }
  162.       }
  163.  
  164.    }
  165. }
  166.